package com.qyl.hrm.utils;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.util.Random;

public class GetCheck {

    static Random random = new Random();
	public static String getRandom(){
		
		String check = ""; 
		for(int i=0;i<4;i++){
			int ran = random.nextInt(10);
			check = ran + check;
			
		}		
		return check;
	}
	
	public static BufferedImage getCheckImg(String code){
		
		//创建画布
		BufferedImage bufferedImage = new BufferedImage(88, 20, BufferedImage.TYPE_INT_RGB);
		
		//创建画笔
		Graphics graphics = bufferedImage.getGraphics();
		//设置画布颜色
		graphics.setColor(Color.yellow);
		//画出矩形
		graphics.fillRect(0, 0, 88, 20);
		//设置字体颜色
		graphics.setColor(Color.black);
		
		graphics.setFont(new Font("宋体", Font.BOLD, 18));
		//循环写入字符串
		for(int i = 0;i<code.length();i++){
			
			char c = code.charAt(i);
			graphics.drawString(c+"", i*22, 20);
		}
		
		return bufferedImage;
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		String random = GetCheck.getRandom();
		System.out.println(random);

		
	}

}
